﻿using PMIS.WebApi.Extensions;
using Serilog;
using Serilog.Events;

namespace PMIS.WebApi.Middleware
{
    public static class SerilogMiddleware
    {
        public static IHostBuilder UseSerilogMiddleware(this IHostBuilder builder)
        {
            return builder.UseSerilog((context, logger) =>
            {
                logger.Enrich.FromLogContext();
                logger.MinimumLevel.Debug();
                logger.MinimumLevel.Override("Microsoft", LogEventLevel.Information);
                logger.MinimumLevel.Override("Default", LogEventLevel.Information);
                logger.MinimumLevel.Override("System", LogEventLevel.Information);

                //输出到控制台
                logger.WriteToConsole();

                foreach (LogEventLevel logEvent in Enum.GetValues(typeof(LogEventLevel)))
                {
                    logger.WriteToFile(context, logEvent);
                }

                //logger.WriteToDb();
            });
        }
    }
}
